package com.ly.spring.mvc;

import com.ly.spring.mvc.web.DateConvertor;
import com.ly.spring.mvc.web.MyReqHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
@ComponentScan("com.ly.spring.mvc")
// @EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void configureDefaultServletHandling(
            DefaultServletHandlerConfigurer configurer) {
        // 开启静态资源访问功能
        configurer.enable();
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/uploadHead/**")
                // :file  外部文件路径
                .addResourceLocations("file:F:/上课视频/143/1116/");
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new DateConvertor());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyReqHandler())
                .addPathPatterns("/**");
    }

    @Bean
    MultipartResolver multipartResolver(){
        return new StandardServletMultipartResolver();
    }
}
